echo
echo '欢迎使用本工具安装rancher，注意查看密码时，需要等待安装日志刷新 半 分钟左右，按CTRL+C结束，重新运行本程序即可'
echo
echo '1、安装rancher最新版'
echo '2、卸载rancher'
echo '3、查看随机密码'
echo
read -p '请输入你需要进行的操作：' operate

a='1'
b='2'
c='3'

if [ $operate = $a ]
 then 

echo '正在创建 数据 目录：/usr/local/rancher/rancher_master/data/rancher_home/rancher……'
mkdir -p /usr/local/rancher/rancher_master/data/rancher_home/rancher
echo '正在创建 日志 目录：/usr/local/rancher/rancher_master/data/rancher_home/auditlog……'
mkdir -p /usr/local/rancher/rancher_master/data/rancher_home/auditlog

read -p '请输入网页的端口（必填，一般 80 ）' web_port
read -p '请输入https的端口（必填，一般 443 ）' https_port

echo '开始安装rancher/rancher:latest……'
docker run -d \
--privileged \
--restart=unless-stopped \
-p $web_port:80 \
-p $https_port:443 \
-v /usr/local/rancher/rancher_master/data/rancher_home/rancher:/var/lib/rancher \
-v /usr/local/rancher/rancher_master/data/rancher_home/auditlog:/var/log/auditlog \
--name cloud_rancher rancher/rancher:latest

echo '输出日志……'
docker logs -f cloud_rancher

fi

if [ $operate = $b ]
then 
    echo '开始删除docker容器……'
    docker rm -f cloud_rancher
	cd /usr/local/
    echo '进入rancher所在目录……'
    pwd
    echo '开始删除rancher文件……'
	rm -rf rancher
    echo 'rancher文件已删除……'
    echo '卸载结束'
fi

if [ $operate = $c ]
then
	echo '当前产生的随机密码为：'
	docker logs cloud_rancher  2>&1 | grep "Bootstrap Password:"

fi